package com.fishingwithme.infrastructure.dtos;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

@Getter
@Setter
public class DTO<T> implements Serializable {
    private T data;
    private String msg = "success";
    private Boolean status;
    private Integer code = 200;


    public DTO() {
    }

    public DTO(T data) {
        this.data = data;
        this.status = Boolean.TRUE;
    }

    public DTO(T data, Boolean status) {
        this.data = data;
        this.status = status;
    }

    public DTO(T data, Boolean status, String msg) {
        this.data = data;
        this.status = status;
    }

    public DTO(T data, int code, Boolean status, String msg) {
        this.status = status;
        this.code = code;
        this.data = data;
        this.msg = msg;
    }


    public static <T> DTO<T> success(T data) {
        return new DTO<T>(data, Boolean.TRUE);
    }

    public static <T> DTO<T> fail(T data, String msg) {
        return new DTO<T>(data, 400,Boolean.FALSE, msg);

    }

    public static <T> DTO<T> fail(T data, int code, String msg) {
        return new DTO<>(data, code, Boolean.FALSE, msg);
    }

    public static <T> DTO<T> fail(String error) {
        return new DTO<>(null,400,Boolean.FALSE,error);

    }
}
